package collectionFramework;

import java.util.HashSet;
import java.util.Iterator;

public class MyHashSetRetrieve {

	public static void main(String[] args) {
		HashSet<Integer> hs = new HashSet<Integer>();
		hs.add(80);
		hs.add(50);
		hs.add(70);
		hs.add(10);
		hs.add(30);

		System.out.print("HashSet Object: ");
		System.out.println(hs);

		// using for-each Loop
		/*
		 * System.out.println("HashSet Elements (ForEach Loop): "); for (Object
		 * obj : hs) System.out.println(obj);
		 */
		// using Iterator
		System.out.println("HashSet Elements (Iterator): ");
		Iterator<Integer> it = hs.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
			// to remove single element
			it.remove();
		}
		System.out.println(hs);
	}
}
